package com.xbongbong.pro.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;

/**
 * 公用配置 + 静态配置
 * @author kaka
 * @time 2018-8-28 19:25
 */
@Getter
@Setter
@Component
public class ProBaseConfig {

    @Getter
    private static String projectName;
    @Getter
    private static String esName;

    /**
     * 注意：钉钉微应用appId，不是我们paas应用对应的appId
     */
    @Getter
    private static String appId;

    /**
     * 钉钉微应用suiteKey
     */
    @Getter
    private static String suiteKey;

    /**
     *  钉钉微应用suiteSecret
     */
    @Getter
    private static String suiteSecret;

    @Getter
    private static String localUrl;

    /**
     * dingtalk前端地址
     */
    @Getter
    private static String dingtalkFrontUrl;

    /**
     * api地址
     */
    @Getter
    private static String apiUrl;

    /**
     * 栗子AK (搜客)
     */
    @Getter
    private static String clueAk;

    /**
     * 栗子AS (搜客)
     */
    @Getter
    private static String clueAs;

    @Getter
    private static String xbbCorpId;

    @Getter
    private static String xbbUserId;

    @Getter
    private static String betaInfo = "";

    @Getter
    private static String proCorpId;

    @Getter
    private static String proUserId;

    @Getter
    private static Long proOppFormId;

    @Getter
    private static Long proCusFormId;

    /**
     * 价值攻略
     */
    @Getter
    private static Long proRaidersGroupId;

    /**
     * 流量回放token
     */
    @Getter
    private static String xbbPlayBackToken;

    /**
     * 流量回放url
     */
    @Getter
    private static String xbbPlayBackUrl;

    /**
     * web前端项目地址
     */
    @Value("${com.xbongbong.dingxbb.dingtalk.pushFrontUrl}")
    private String pushFrontUrl;

    @Value("${com.xbongbong.dingxbb.web.frontUrl}")
    private String webFrontUrl;

    @Value("${com.xbongbong.dingxbb.dingtalk.url}")
    private String projectDingtalkUrl;

    /**
     * pro 扫码登录 scanAppId
     */
    @Value("${com.xbongbong.pro.main.scan.appid}")
    private String scanAppId;

    /**
     * pro 扫码登录 scanAppSecret
     */
    @Value("${com.xbongbong.pro.main.scan.appSecret}")
    private String scanAppSecret;

    /**
     * 用于验证
     */
    @Value("${com.xbongbong.xbbcode}")
    private String xbbCode;

    /**
     * 阿里云/零售云oss accessKeyId
     */
    @Value("${com.xbongbong.pro.oss.accessKeyId}")
    private String ossAccessKeyId;

    /**
     * 阿里云/零售云oss accessKeySecret
     */
    @Value("${com.xbongbong.pro.oss.accessKeySecret}")
    private String accessKeySecret;

    /**
     * 阿里云/零售云oss roleArn
     */
    @Value("${com.xbongbong.pro.oss.roleArn}")
    private String roleArn;

    /**
     * 阿里云/零售云oss region
     */
    @Value("${com.xbongbong.pro.oss.region}")
    private String region;

    /**
     * 阿里云/零售云oss stsEndPoint
     */
    @Value("${com.xbongbong.pro.oss.stsEndPoint}")
    private String stsEndPoint;

    /**
     * 阿里云/零售云oss endpoint带协议，如http://
     */
    @Value("${com.xbongbong.pro.oss.endpoint}")
    private String endpoint;

    /**
     * 阿里云/零售云oss endpoint,不带协议的字符串
     */
    @Value("${com.xbongbong.pro.oss.endpointSimple}")
    private String endpointSimple;

    /**
     * 阿里云/零售云oss 内网endpoint,不带协议的字符串
     */
    @Value("${com.xbongbong.pro.oss.internalEndpointSimple}")
    private String internalEndpointSimple;

    /**
     * 阿里云/零售云oss 资源域名
     */
    @Value("${com.xbongbong.pro.oss.viewurl}")
    private String viewurl;

    /**
     * 阿里云/零售云oss bucketName
     */
    @Value("${com.xbongbong.pro.oss.bucketName}")
    private String bucketName;

    /**
     * 阿里云/零售云oss accessKeyId
     */
    @Value("${com.xbongbong.pro.oss.callCenterAccessKeyId}")
    private String callCenterAccessKeyId;

    /**
     * 阿里云/零售云oss accessKeySecret
     */
    @Value("${com.xbongbong.pro.oss.callCenterAccessKeySecret}")
    private String callCenterAccessKeySecret;

    /**
     * 阿里云/零售云oss endpoint带协议，如http://
     */
    @Value("${com.xbongbong.pro.oss.callCenterEndpoint}")
    private String callCenterEndpoint;

    /**
     * 阿里云/零售云oss 资源域名
     */
    @Value("${com.xbongbong.pro.oss.callCenterViewurl}")
    private String callCenterViewurl;

    /**
     * 阿里云/零售云oss bucketName
     */
    @Value("${com.xbongbong.pro.oss.callCenterBucketName}")
    private String callCenterBucketName;

    @Resource
    private Environment env;
    
    @Value("${com.xbongbong.dingxbb.dingtalk.groupTemplateId}")
    private String groupTemplateId;

    /**
     * 阿里云/零售云oss accessKeyId
     */
    @Value("${com.xbongbong.pro.oss.lowCodeAccessKeyId}")
    private String lowCodeAccessKeyId;

    /**
     * 经销商web端登录地址
     */
    @Getter
    private static String distributorLoginUrl;

    @Getter
    private static String weChatApplyUrl;


    /**
     * 阿里云/零售云oss accessKeySecret
     */
    @Value("${com.xbongbong.pro.oss.lowCodeAccessKeySecret}")
    private String lowCodeAccessKeySecret;

    /**
     * 阿里云/零售云oss endpoint带协议，如http://
     */
    @Value("${com.xbongbong.pro.oss.lowCodeEndpoint}")
    private String lowCodeEndpoint;

    /**
     * 阿里云/零售云oss endpoint,不带协议的字符串
     */
    @Value("${com.xbongbong.pro.oss.lowCodeEndpointSimple}")
    private String lowCodeEndpointSimple;
    /**
     * 阿里云/零售云oss 内网endpoint,不带协议的字符串
     */
    @Value("${com.xbongbong.pro.oss.lowCodeInternalEndpointSimple}")
    private String lowCodeInternalEndpointSimple;
    /**
     * 阿里云/零售云oss bucketName
     */
    @Value("${com.xbongbong.pro.oss.lowCodeBucketName}")
    private String lowCodeBucketName;
    /**
     * 精线索调用地址
     */
    @Value("${com.xbongbong.fineClue.url}")
    private String fineClueUrl;

    /**
     * 精线索加密编码
     */
    @Value("${com.xbongbong.fineClue.key}")
    private String fineClueKey;


    /**
     * 最大上传文件
     */
    @Getter
    private static String maxFileSize;

    @Value("${com.xbongbong.pro.aliyunCallcenter.chartUrl}")
    private String aliyunCallcenterChartUrl;

    @Value("${com.xbongbong.pro.aiCenter.chartUrl}")
    private String aiCenterChartUrl;

    /**
     * 酷应用
     */
    @Value("${com.xbongbong.coolAppCode}")
    private String coolAppCode;
    /**
     * 机器人
     */
    @Value("${com.xbongbong.robotCode}")
    private String robotCode;

    /**
     * 钉钉消息模板map
     */
    @Getter
    @Value("#{${com.xbongbong.message.templates}}")
    private Map<String, String> templates;

    @Value("${com.xbongbong.gray}")
    private Integer gray;


    /**
     * sso登录地址
     */
    @Value("${com.xbongbong.dingxbb.sso.loginUrl}")
    private String ssoLoginUrl;
    /**
     * sso登录重定向地址
     */
    @Value("${com.xbongbong.dingxbb.sso.redirectLoginUrl}")
    private String redirectLoginUrl;

    /**
     * sso授权码接收地址
     */
    @Value("${com.xbongbong.dingxbb.sso.redirectUrl}")
    private String ssoRedirectUrl;

    @PostConstruct
    public void readConfig() {
        projectName = env.getProperty("com.xbongbong.pro.main.name");
        esName = env.getProperty("com.xbongbong.pro.main.esname");
        appId = env.getProperty("com.xbongbong.dingxbb.dingtalk.appid");
        suiteKey = env.getProperty("com.xbongbong.dingxbb.dingtalk.suite.key");
        suiteSecret = env.getProperty("com.xbongbong.dingxbb.dingtalk.suite.secret");
        localUrl = env.getProperty("com.xbongbong.dingxbb.dingtalk.url");
        dingtalkFrontUrl = env.getProperty("com.xbongbong.dingxbb.dingtalk.frontUrl");
        apiUrl = env.getProperty("com.xbongbong.dingxbb.api.url");
        clueAk = env.getProperty("com.xbongbong.clue.ak");
        clueAs = env.getProperty("com.xbongbong.clue.as");
        xbbCorpId = env.getProperty("com.xbongbong.xbbCorpId");
        xbbUserId = env.getProperty("com.xbongbong.xbbUserId");
        groupTemplateId = env.getProperty("com.xbongbong.dingxbb.dingtalk.groupTemplateId");
        proCorpId = env.getProperty("com.xbongbong.proCorpId");
        proUserId = env.getProperty("com.xbongbong.proUserId");
        proOppFormId = env.getProperty("com.xbongbong.proOppFormId", Long.class);
        proCusFormId = env.getProperty("com.xbongbong.proCusFormId", Long.class);
        proRaidersGroupId = env.getProperty("raiders.group", Long.class);
        xbbPlayBackToken = env.getProperty("com.xbongbong.xbbPlayBackToken");
        xbbPlayBackUrl = env.getProperty("com.xbongbong.xbbPlayBackUrl");
        distributorLoginUrl = env.getProperty("distributor.loginUrl");
        weChatApplyUrl = env.getProperty("com.xbongbong.weChat.applyUrl");
        maxFileSize = env.getProperty("spring.servlet.multipart.max-file-size");
    }

    @Profile({"test-beta","prdbeta"})
    @Bean("proBeta")
    public String betaConfig() {
        betaInfo = "beta";
        return betaInfo;
    }
}
